#include "Hello.h"
#include <iostream>

Hello::Hello()
{
    //ctor
}

Hello::~Hello()
{
    //dtor
}
bool Hello::Initialize()
{
    layerScreen = CreateLayer(640,480);
    thingMonster = layerScreen->CreateSprite("../../resource/thing_monster.png",400,388);
    thingMonster->bVisible = false;
    thingFont = layerScreen->CreateSprite("../../resource/font1.jpg",32,32);
    thingFont->AddAnimation(1,true,0,10);
    thingFont->SetCurrentAnimation(0);
    thingFont->Position.fx = 80;
    thingFont->Position.fy = 10;
    Speed = CVector(133,170);
    return true;
}

void Hello::TestCollide()
{
    if(thingFont->Position.fx > CVideoManager::getInstance()->WindowSize.fx){
        Speed.fx = -Speed.fx;
        thingFont->Position.fx = CVideoManager::getInstance()->WindowSize.fx;
    }else if(thingFont->Position.fx < 0){
        Speed.fx = -Speed.fx;
        thingFont->Position.fx = 0;
    }

    if(thingFont->Position.fy > CVideoManager::getInstance()->WindowSize.fy){
        Speed.fy = -Speed.fy;
        thingFont->Position.fy = CVideoManager::getInstance()->WindowSize.fy;
    }else if(thingFont->Position.fy < 0){
        Speed.fy = -Speed.fy;
        thingFont->Position.fy = 0;
    }
}

void Hello::MoveSprite()
{
    thingFont->Position.fx += Speed.fx * CTimerManager::getInstance()->fFrameTime;
    thingFont->Position.fy += Speed.fy * CTimerManager::getInstance()->fFrameTime;
}

void Hello::Execute()
{
    MoveSprite();
    TestCollide();
}

bool Hello::Release()
{
    return true;
}
